package com.joy.pricture.ui;

import javax.swing.*;

/**
 * 图片小方格类
 */
public class Cell extends JButton {
    //带有图片的小方格
    public Cell(Icon icon) {
        super(icon);
        this.setSize(150,150);
    }
    //带有图片并且有序号的小方格
    public Cell(String text, Icon icon) {
        super(text, icon);
        this.setSize(150,150);
        this.setHorizontalTextPosition(CENTER);//序号水平居中显示
        this.setVerticalTextPosition(CENTER);//序号垂直居中显示
    }
    //当前方格的移动
    public void move(String direction){
        switch (direction){
            case "UP":
                this.setLocation(this.getBounds().x,this.getBounds().y-150);
                break;
            case "DOWN":
                this.setLocation(this.getBounds().x,this.getBounds().y+150);
                break;
            case "LEFT":
                this.setLocation(this.getBounds().x-150,this.getBounds().y);
                break;
            case "RIGHT":
                this.setLocation(this.getBounds().x+150,this.getBounds().y);
                break;
            default://其他方向，不做处理
                break;
        }
    }
}
